﻿using System;
using System.Collections.Generic;
using System.Text;
using GraphLib;

namespace Test3
{
    class Edge : GraphLib.IEdge
    {
        Vertex m_start;
        Vertex m_finish;
        string m_name;
        double m_weight;

        public double Weight
        {
            get { return m_weight;}
            set { m_weight = value;}
        }

        public string GetName()
        {
            return m_name;
        }
        public IVertex GetStart()
        {
            return (m_start as IVertex);
        }
        public IVertex GetFinish()
        {
            return (m_finish as IVertex);
        }

        public Edge(string _name,Vertex start, Vertex finish, double _Weight)
        {
            m_start = start;
            m_finish = finish;
            m_name = _name;
            m_weight = _Weight;
        }
    }

    class Vertex : GraphLib.IVertex
    {
        private string m_name;
        public int deg;
        //private int m_SortNum;
        private double m_weight;
        private GraphLib.Graph<Vertex,Edge> m_graph;

        //public int SortNum { get { return m_SortNum; } set { m_SortNum = value; } }

        //public void SetGraph(GraphLib.Graph<Vertex, Edge> graph)
        //{
            //m_graph = graph as GraphLib.Graph<Vertex, Edge>;
        //}

        public double Weight
        {
            get { return m_weight; }
            set { m_weight = value; }
        }

        public string GetName()
        {
            return m_name;
        }

        public Vertex(string _name)
        {
            m_name = _name;
        }
    }

    class Program
    {
        public static Graph<Vertex, Edge> g = new Graph<Vertex, Edge>();

        //public static IGraph igraph = (g as IGraph);
        static void Main(string[] args)
        {
/*            for (int i = 1; i <= 6; i++)
            {
                Vertex v = new Vertex(i.ToString());
                v.Weight = 0;
                igraph.AddVertex(v as IVertex);
            }
            igraph.AddEdge(new Edge("link12", igraph.GetVertex("1") as Vertex, igraph.GetVertex("2") as Vertex,1));
            igraph.AddEdge(new Edge("link23", igraph.GetVertex("2") as Vertex, igraph.GetVertex("3") as Vertex, 5));
            igraph.AddEdge(new Edge("link24", igraph.GetVertex("2") as Vertex, igraph.GetVertex("4") as Vertex, 2));
            igraph.AddEdge(new Edge("link26", igraph.GetVertex("2") as Vertex, igraph.GetVertex("6") as Vertex, 7));
            igraph.AddEdge(new Edge("link36", igraph.GetVertex("3") as Vertex, igraph.GetVertex("6") as Vertex, 1));
            igraph.AddEdge(new Edge("link41", igraph.GetVertex("4") as Vertex, igraph.GetVertex("1") as Vertex, 2));
            igraph.AddEdge(new Edge("link43", igraph.GetVertex("4") as Vertex, igraph.GetVertex("3") as Vertex, 1));
            igraph.AddEdge(new Edge("link45", igraph.GetVertex("4") as Vertex, igraph.GetVertex("5") as Vertex, 4));
            igraph.AddEdge(new Edge("link54", igraph.GetVertex("5") as Vertex, igraph.GetVertex("4") as Vertex, 3));
            igraph.AddEdge(new Edge("link65", igraph.GetVertex("6") as Vertex, igraph.GetVertex("5") as Vertex, 1));

            List<IVertex> lst =  igraph.DeyxtraAlg("1", "5");
            foreach (IVertex v in lst)
                Console.WriteLine(v.GetName());
 */

/*            for (int i = 1; i <= 4; i++)
            {
                Vertex v = new Vertex(i.ToString());
                v.Weight = 0;
                g.AddVertex(v as IVertex,g);
            }
            g.AddEdge(new Edge("link12", g.GetVertex("1") as Vertex, g.GetVertex("2") as Vertex, 1));
            //igraph.AddEdge(new Edge("link15", igraph.GetVertex("1") as Vertex, igraph.GetVertex("5") as Vertex, 1));
            g.AddEdge(new Edge("link23", g.GetVertex("2") as Vertex, g.GetVertex("3") as Vertex, 5));
            g.AddEdge(new Edge("link34", g.GetVertex("3") as Vertex, g.GetVertex("4") as Vertex, 2));
            g.AddEdge(new Edge("link41", g.GetVertex("4") as Vertex, g.GetVertex("1") as Vertex, 7));
            List<IVertex> lst = g.EulerCycl("1");
            foreach (IVertex v in lst)
                Console.WriteLine(v.GetName());
*/            

            #region Проверка добавления вершин
            //for (int i = 0; i < 7; i++)
            //{
            //    Vertex v = new Vertex(i.ToString());
            //    v.deg = i;
            //    v.Weight = i;
            //    g.AddVertex(v);
            //}
            for (int i = 0; i < 4; i++)
            {
                Vertex v = new Vertex(i.ToString());
                v.deg = i;
                v.Weight = i;
                g.AddVertex(v);
            }

            #endregion

            #region Проверка получения вершин
            //Console.WriteLine();
            //Console.WriteLine("GetVertex");
            //Vertex _v = (igraph.GetVertex("3") as Vertex);
            //if (_v != null)
            //    Console.WriteLine(_v.deg);
            //else Console.WriteLine("not exist");
            #endregion

            #region Проверка добавления рёбер
            //Edge e = new Edge("link1", (igraph.GetVertex("3") as Vertex), (igraph.GetVertex("2") as Vertex));
            //igraph.AddEdge(e);
            #endregion

            #region Проверка получения рёбер
            //Console.WriteLine();
            //Console.WriteLine("GetEdge");
            //Edge _e = igraph.GetEdge("link1") as Edge;
            //if (_e != null)
            //{
            //    Console.WriteLine("deg start - " + (_e.GetStart() as Vertex).deg);
            //    Console.WriteLine("deg finish - " + (_e.GetFinish() as Vertex).deg);
            //}
            //else Console.WriteLine("not exist");
            #endregion

            #region Проверка удаления рёбер
            ////Console.WriteLine();
            ////Console.WriteLine("RemoveEdge");
            ////igraph.RemoveEdge("link1");
            ////_e = igraph.GetEdge("link1") as Edge;
            ////if (_e != null)
            ////{
            ////    Console.WriteLine("deg start - " + (_e.GetStart() as Vertex).deg);
            ////    Console.WriteLine("deg finish - " + (_e.GetFinish() as Vertex).deg);
            ////}
            ////else Console.WriteLine("not exist");
            #endregion

            #region Проверка удаления вершин
            //Console.WriteLine();
            //Console.WriteLine("RemoveVertex");
            //igraph.RemoveVertex("3");
            //_v = (igraph.GetVertex("3") as Vertex);
            //if (_v != null)
            //    Console.WriteLine(_v.deg);
            //else Console.WriteLine("not exist");
            //_e = igraph.GetEdge("link1") as Edge;
            //if (_e != null)
            //{
            //    Console.WriteLine("deg start - " + (_e.GetStart() as Vertex).deg);
            //    Console.WriteLine("deg finish - " + (_e.GetFinish() as Vertex).deg);
            //}
            //else Console.WriteLine("not exist");

            #endregion

            #region Проверка обхода в глубину
            g.AddEdge(new Edge("link2", g.GetVertex("0"), g.GetVertex("3"), 0));
            //g.AddEdge(new Edge("link3", g.GetVertex("3"), g.GetVertex("2"), 0));
            g.AddEdge(new Edge("link4", g.GetVertex("3"), g.GetVertex("2"), 0));
            g.AddEdge(new Edge("link5", g.GetVertex("2"), g.GetVertex("1"), 0));
            g.AddEdge(new Edge("link7", g.GetVertex("1"), g.GetVertex("0"), 0));
           // g.AddEdge(new Edge("link71", g.GetVertex("3"), g.GetVertex("1"), 0));
           // g.AddEdge(new Edge("link71", g.GetVertex("1"), g.GetVertex("3"), 0));
            //            g.AddEdge(new Edge("link9", g.GetVertex("1"), g.GetVertex("2"), 0));


            //g.AddEdge(new Edge("link2", g.GetVertex("0"), g.GetVertex("2"), 0));
            //g.AddEdge(new Edge("link4", g.GetVertex("0"), g.GetVertex("4"), 0));
            //g.AddEdge(new Edge("link3", g.GetVertex("1"), g.GetVertex("3"), 0));
            //g.AddEdge(new Edge("link5", g.GetVertex("3"), g.GetVertex("5"), 0));
            ////g.AddEdge(new Edge("link6", g.GetVertex("5") as Vertex, g.GetVertex("1") as Vertex, 0));
            //g.AddEdge(new Edge("link7", g.GetVertex("5"), g.GetVertex("6"), 0));

            Console.WriteLine("Topologsort");
            List<Vertex> res = g.TopologSort();
            foreach (Vertex v in res)
            {
                Console.WriteLine(v.GetName());
                //Console.WriteLine(i.ToString() + " - " + g.GetVertex(i.ToString()).SortNum.ToString());
            }
            Console.WriteLine("Topologsort finished");


            //Console.WriteLine("SerachDepth");
            //List<Vertex> resSearch = g.DepthSearch("0", "3");
            //foreach (Vertex v in resSearch)
            //    Console.WriteLine(v.deg);
            #endregion
            
            
            Console.ReadLine();
            
        }
    }
}
